home *** CD-ROM | disk | FTP | other *** search
-
- /* Copyright (C) 2009 Norman Solomon
- * e-mail: historytree.addon@yahoo.com
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the License.
- */
-
- // ***********************************************************************
- // ***** *****
- // ***** WEB-PAGE DESCRIPTION AND URL SEARCH FUNCTIONS *****
- // ***** ------------------------------------------------------- *****
- // ***** Creates search array, searches and displays results *****
- // ***** Functions called from "historyViewer.xul" EventHandlers *****
- // ***** *****
- // ***********************************************************************
-
- // ============================================================
- // Called from <image...> onclick() event handlers. BUT make
- // sure txtToFind exists BEFORE calling (else inifinite loop)
- // ============================================================
- function searchTree(findNext, txtToFind, searchURL)
- {
- // Init vars
- var btnFindNext; // <image...> button
- var btnFindPrev; // <image...> button
- var hNodeNdx; // Integer
- var hNode; // HistoryNode
- var tNode; // TreeNode
- var matchFound; // boolean
-
- // ----------------------------------------
- // Stop setTimout() and set global flag
- clearTimeout(gTimeoutInterval);
- gTimeoutInterval = null;
-
- // Set search button image to button-out
- if (findNext)
- {
- btnFindNext = document.getElementById("btnFindNext");
- btnFindNext.src = "images/btnNextOut.gif";
- }
- else
- {
- btnFindPrev = document.getElementById("btnFindPrev");
- btnFindPrev.src = "images/btnPrevOut.gif";
- }
-
- // ------------------------------------------
- // Clear currently highlighted node (if any)
- if (gSearchNdx >= 0)
- {
- hNodeNdx = gSearchIndexes[gSearchNdx];
- hNode = gNodeList[hNodeNdx];
- tNode = gTreeNodes[hNode.treeNodeNdx + 1];
- if (!tNode.hidden)
- {
- // Clear highlighted node depending on view
- if (gCurrentView === TREE_VIEW)
- {
- // Draw TV node box and the text inside it
- drawNodeBoxWithTextInside(tNode, false);
- }
- else
- {
- // Draw GV image and description
- drawGridViewImage(tNode, false);
- drawGridViewDescription(tNode, false);
- }
- }
- }
-
- // -----------------------------------------------
- // Do "loop-around" search from current gSearchNdx
- matchFound = false;
- while (!matchFound)
- {
- // Set Next/Prev "loop-around" gSearchNdx
- if (findNext)
- {
- gSearchNdx ++;
- if (gSearchNdx >= gSearchIndexes.length)
- gSearchNdx = 0;
- }
- else
- {
- gSearchNdx --;
- if (gSearchNdx < 0)
- gSearchNdx = gSearchIndexes.length - 1;
- }
-
- // Get hNode using gSearchNdx pointer
- hNodeNdx = gSearchIndexes[gSearchNdx];
- hNode = gNodeList[hNodeNdx];
-
- // Search web-page description for passed txtToFind
- if (hNode.uCaseDesc.indexOf(txtToFind) !== -1)
- {
- matchFound = true;
- }
- else if (searchURL)
- {
- // Search web-page URL for passed txtToFind
- if (hNode.uCaseUri.indexOf(txtToFind) !== -1)
- matchFound = true;
- }
- }
-
- // --------------------------------------------------
- // Scroll to, display and highlight the found hNode
- highlightGVorTVnode(hNode);
- }
-
- // ======================================================
- // Scrolls to, displays and highlights the passed hNode
- // Highlights GV or TV nodes found via Find Next/Prev
- // ======================================================
- function highlightGVorTVnode(hNode)
- {
- // Init vars
- var tNode; // TreeNode
- var optGrpView; // <radiogroup...>
- var sldDraw; // <scale...>
- var numAcross; // Integer
-
- // --------------------------------------------------
- // Get corresponding TreeNode from gTreeNodes[]
- tNode = gTreeNodes[hNode.treeNodeNdx + 1];
-
- // Process differs for visible and invisible nodes
- if (!tNode.hidden)
- {
- // Scroll visible tNode into view (for GV and TV)
- scrollNodeIntoView(tNode);
-
- // Highlight node depending on view
- if (gCurrentView === TREE_VIEW)
- {
- // If an expanded image is currently visible clear it
- if (gExpandedNode !== null)
- {
- drawTree(false, null, null);
- gExpandedNode = null;
- }
- else
- {
- // Draw TV node box and the text inside it
- drawNodeBoxWithTextInside(tNode, true);
- }
- }
- else
- {
- // Draw GV image and description
- drawGridViewImage(tNode, true);
- drawGridViewDescription(tNode, true);
- }
- }
- else
- {
- // tNode is hidden - Expand all sub-trees for current quick-view
- optGrpView = document.getElementById("optGrpView");
- setTreeNodePointersForSelectedQuickView(optGrpView.selectedIndex);
-
- // If tNode is STILL hidden change to required quick-view
- if (tNode.hidden)
- {
- if (isOpenTab(hNode.tab))
- {
- // Hidden found tNode is in an open FF Tab
- optGrpView.selectedIndex = 0;
- setTreePointersFor_OpenTabsQuickView();
- }
- else
- {
- // Hidden found tNode is in a closed FF Tab
- optGrpView.selectedIndex = 3;
- setTreePointersFor_ClosedTabsQuickView();
- }
- }
-
- // Draw req GV or TV quick-view on gCanvas
- if (gCurrentView === TREE_VIEW)
- {
- // Draw TV with found tNode highlighted, where
- // scrolling tNode into view is done in drawTree()
- drawTree(false, null, tNode);
- }
- else
- {
- // Draw GV quick-view using req number of images per row
- sldDraw = document.getElementById("sldDraw");
- numAcross = (sldDraw.max - sldDraw.value) + 3;
- drawAllImagesOnCanvas(numAcross, true);
-
- // GV tNode(x,y) is set - So can scroll it into view
- scrollNodeIntoView(tNode);
- }
- }
- }
-
- // =============================================================
- // Creates gSearchIndexes[] - Enabling consistant search order
- // =============================================================
- function createGlobalSearchIndexesArray()
- {
- // Init vars
- var tabRoot, tNode; // TreeNode's
- var tabID; // FF Tab tabID
- var addOpenPage; // Boolean
- var hNode; // HistoryNode
-
- // -----------------------------------------------------
- // Indexes are added Tab-by-Tab, in FF Tab display order
- for (var i = 0; i < gTabRoots.length; i++)
- {
- tabRoot = gTabRoots[i];
- tabID = tabRoot.histNode.tab;
-
- // Add indexes for this Tab in the order they were added
- // to gNodeList[] - open pages first, then closed pages
- for (var tf = 0; tf < 2; tf++)
- {
- // Set flag used in for(j) loop, below
- if (tf === 0)
- addOpenPage = true;
- else
- addOpenPage = false;
-
- // Two passes down gNodeList[] are made for each tabID
- for (var j = 0; j < gNodeList.length; j++)
- {
- // Add index for open or closed page
- hNode = gNodeList[j];
- tNode = gTreeNodes[hNode.treeNodeNdx + 1]; // + 1 for added Root
- if (hNode.tab === tabID && tNode.isOpenPage === addOpenPage)
- {
- // Add gNodeList[] index to global search array
- gSearchIndexes.push(j);
- }
- }
- }
- }
- }
-
- // ============================================================
- // Returns true if <textbox...> text is found in gNodeList[]
- // Both the desc AND the URL are searched if searchURL = true
- // ============================================================
- function searchTextFound(txtToFind, searchURL)
- {
- // Init vars
- var hNodeNdx;
- var hNode;
-
- // --------------------------------------------------
- // Search for matching web-page description and URL
- for (var i = 0; i < gSearchIndexes.length; i++)
- {
- // Get hNode using gSearchIndexes[] pointer
- hNodeNdx = gSearchIndexes[i];
- hNode = gNodeList[hNodeNdx];
-
- // Search web-page description for passed txtToFind
- if (hNode.uCaseDesc.indexOf(txtToFind) !== -1)
- {
- return true;
- }
- else if (searchURL)
- {
- // Search web-page URL for passed txtToFind
- if (hNode.uCaseUri.indexOf(txtToFind) !== -1)
- return true;
- }
- }
-
- // Search text was not found in desc or URL
- return false;
- }
-
- // =========================================================
- // Scrolls gCanvas so that found hNode is visible on screen
- // Takes account of current window size and gCurrentView
- // =========================================================
- function scrollNodeIntoView(tNode)
- {
- // Init integer vars
- var xChange, yChange;
- var wx, wy, ww, wh, wb, wr;
- var nx, ny, nw, nh, nb, nr;
-
- // Init objects
- var xs = {};
- var ys = {};
- var tNode;
-
- // ---------------------------------------------
- // Get this window's wx, wy, ww, wh, wb, wr
- gCanvasScroller.getPosition(xs, ys);
- wx = xs.value;
- wy = ys.value;
- ww = this.innerWidth;
- wh = this.innerHeight - gCanvas.offsetTop;
- wb = wy + wh;
- wr = wx + ww;
-
- // Get TreeNode's nx, ny, nw, nh, nb, nr
- if (gCurrentView === TREE_VIEW)
- {
- nx = tNode.pos.x;
- ny = tNode.pos.y;
- nw = tNode.width;
- nh = tNode.height + BOX_BTN_HGT;
- nb = ny + nh;
- nr = nx + nw;
- }
- else
- {
- nx = tNode.gridViewImgX;
- ny = tNode.gridViewImgY;
- nw = tNode.gridViewImgWid;
- nh = Math.round(nw * WH_RATIO) + GV_VGAP;
- nb = ny + nh;
- nr = nx + nw;
- }
-
- // ---------------------------------------------
- // Calculate scrollBy(x) using above values
- if (nr < ww)
- xChange = wx * (-1); // Scroll to zero x
- else if (nr > wr)
- xChange = nr - wr; // Scroll right
- else if (nx < wx)
- xChange = nx - wx; // Scroll left
- else
- xChange = 0;
-
- // Calculate scrollBy(y) using above values
- if (nb < wh)
- yChange = wy * (-1); // Scroll to zero y
- else if (nb > wb)
- yChange = nb - wb; // Scroll down
- else if (ny < wy)
- yChange = ny - wy; // Scroll up
- else
- yChange = 0;
-
- // Adjust for better TV or GV appearance
- if (gCurrentView === TREE_VIEW)
- {
- if (xChange < 0) xChange -= 30;
- if (xChange > 0) xChange += 30;
- if (yChange < 0) yChange -= 20;
- if (yChange > 0) yChange += 20;
- }
- else
- {
- if (yChange < 0) yChange -= 15;
- }
-
- // Scroll TreeNode into view
- gCanvasScroller.scrollBy(xChange, yChange);
- }
-
- // =================================================================
- // Sets search <textbox...> background red if search text NOT found
- // =================================================================
- function setSearchTextBoxColor(searchURL)
- {
- // Get text to search for from <textbox...>
- var txtFind = document.getElementById("txtFind");
- var txtToFind = (txtFind.value).toUpperCase();
-
- // ---------------------------------------------------
- // Make <textbox...> background red if text NOT found
- if (gNodeList.length === 0)
- txtFind.style.backgroundColor = "#cccccc"; // Grey
- else if (txtToFind === "" || searchTextFound(txtToFind, searchURL))
- txtFind.style.backgroundColor = "#ffffff"; // White
- else
- txtFind.style.backgroundColor = "#ff9090"; // Red
- }
-
- // =========================================================
- // Returns true if tNode was highlighted via Find Next/Prev
- // =========================================================
- function isHighlightedNode(tNode)
- {
- var hNodeNdx;
- var hNode;
- if (gSearchNdx >= 0)
- {
- hNodeNdx = gSearchIndexes[gSearchNdx];
- hNode = gNodeList[hNodeNdx];
- if (tNode.histNode === hNode)
- return true;
- }
- return false;
- }